package cn.edu.zafu.bigdata.lekang.shiyan8;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class LocalIP {
    public static void main(String[] args) {
        try {
            // 获取本地IP地址
            InetAddress localHost = InetAddress.getLocalHost();
            String ip = localHost.getHostAddress();

            // 输出IP地址
            System.out.println("Your local IP address is: " + ip);
        } catch (UnknownHostException e) {
            // 如果无法解析本地主机名，则打印错误信息
            System.err.println("Error: Could not find local IP address.");
            e.printStackTrace();
        }
    }
}
